package cn.wizzer.app.task.commons.ext.quartz.job;

import cn.wizzer.app.user.modules.models.User;
import cn.wizzer.app.user.modules.services.UserService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.List;


@IocBean
public class UserRebateJob implements Job {

    private static final Log log = Logs.get();
    @Inject
    @Reference
    private UserService userService;


    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.info("定时计算下级返利开始");
        //取出未返利给上级的用户
        List<User> users = userService.query(Cnd.where("is_rebate", "=", 0));
        for (User user : users) {
            userService.userRebateJob(user);
        }
        log.info("定时计算下级返利结束");
    }
}
